package com.sxkiler.demo.seata.controller;


import com.sxkiler.demo.seata.dto.AccountDTO;
import com.sxkiler.demo.seata.service.at.ATAccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/account/at")
public class ATAccountController {

    private Logger logger = LoggerFactory.getLogger(ATAccountController.class);

    @Autowired
    private ATAccountService accountService;

    @PostMapping("/reduce-balance")
    public boolean reduceBalance(@RequestBody AccountDTO accountDTO) throws Exception {
        logger.info("[reduceBalance] 收到扣减余额请求, 用户:{}, 金额:{}", accountDTO.getUserId(), accountDTO.getAmount());
        return accountService.reduceBalance(accountDTO.getUserId(), accountDTO.getAmount());
    }

}
